package tw.com.hitevision.whiteboard.android.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import tw.com.hitevision.whiteboard.android.R;

public class ImageToolbarMenuView extends RelativeLayout {
    private ImageToolbarTrigger imageToolbarTrigger;

    public ImageToolbarMenuView(Context context) {
        super(context);
        init(context);
    }

    public ImageToolbarMenuView(Context context, AttributeSet attr) {
        super(context, attr);
        init(context);
    }

    public ImageToolbarMenuView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        setBackgroundResource(R.drawable.menu_bubble_importimage);
        inflate(context, R.layout.menu_image_toolbar, this);
    }

    public void setImageToolbarListener(ImageToolbarTrigger listener) {
        imageToolbarTrigger = listener;
        setClickListener();
    }

    private void setClickListener(){
        ImageView toolbarAddImage = findViewById(R.id.toolbar_add_image);
        toolbarAddImage.setOnClickListener(v -> {
            if (imageToolbarTrigger!=null) {
                imageToolbarTrigger.triggerAddImage(v);
            }
        });

        ImageView toolbarImageSearch = findViewById(R.id.toolbar_search);
        toolbarImageSearch.setOnClickListener(v -> {
            if (imageToolbarTrigger!=null) {
                imageToolbarTrigger.triggerImageSearch(v);
            }
        });

        ImageView toolbarWebTrimming = findViewById(R.id.toolbar_web);
        toolbarWebTrimming.setOnClickListener(v -> {
            if (imageToolbarTrigger!=null) {
                imageToolbarTrigger.triggerWebTrimming(v);
            }
        });

        ImageView toolbarYoutube = findViewById(R.id.toolbar_youtube);
        toolbarYoutube.setOnClickListener(v -> {
            if (imageToolbarTrigger != null) {
                imageToolbarTrigger.triggerYoutubeVideo(v);
            }
        });
    }

    public interface ImageToolbarTrigger{
        void triggerAddImage(View v);

        void triggerImageSearch(View v);

        void triggerWebTrimming(View v);

        void triggerYoutubeVideo(View v);
    }
}
